package org.swust.sysmonitorapp.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.swust.sysmonitorapp.model.AmqpMessage;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Service
public class MessageStorageService {

    private static final Logger logger = LoggerFactory.getLogger(MessageStorageService.class);
    private final ConcurrentMap<String, AmqpMessage> messageStore = new ConcurrentHashMap<>();

    public void storeMessage(AmqpMessage message) {
        messageStore.put(message.getMessageId(), message);
        logger.info("Stored message: ID={}, Type={}", message.getMessageId(), message.getType());
    }

    public AmqpMessage getMessage(String messageId) {
        return messageStore.get(messageId);
    }

    public void removeMessage(String messageId) {
        messageStore.remove(messageId);
        logger.info("Removed message: ID={}", messageId);
    }
}